<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" />
	<title>员工登录</title>
	<link rel="stylesheet" type="text/css" href="css/public.css">
	<link rel="stylesheet" type="text/css" href="css/index.css">
</head>
<body>
	<div class="cont">
		<div class="content">
			<p class="top">
				<img src="img/top.png">
			</p>
			<h2 class="staff">员工身份验证</h2>
			<div class="info">
				<p class="num"></p>
				<div class="num_wrap">
					<input class="logNum em" type="text" placeholder="请填入您的工号">
					<input class="logNum com" type="text" placeholder="请填入您的公司编号">
					<p class="checkNum">*请输入正确的号码</p>
				</div>
				<p class="name">姓名</p>
				<div class="name_wrap">
					<input class="logName" maxlength="4" type="text" placeholder="请填入您的姓名">
					<p class="checkName">*请输入2-4个中文</p>
				</div>
			</div>
			<div class="ensure">确定</div>
		</div>
	</div>
</body>
<script src="js/jquery-3.1.1.min.js"></script>
<script src="js/vue.min.js"></script>
<script src="js/weixin-common.js" check_auth></script>
<script src="js/app-common.js"></script> 
<script>
	var _url = getParams();
	
	if(_url["type"]){
		$(".num").text("公司");	
		$(".em").hide();
		$(".com").show();
	}else{
		$(".num").text("员工");
		$(".em").show();
		$(".com").hide();
	}

	$(".ensure").on("click",function(){
		var name = $(".logName").val();
        var num = $(".logNum").val();
		checkName(name);
		checkNum(num);
		if(checkName(name) && checkNum(num)){
			$(".ensure").attr('disabled', true);
			var data =  {
				token: getUserToken(),
				name: name
			};
			if(_url["type"]){
				data.team_id = num;
			}else{
				data.employee_id = num;
			}
			$.ajax({
				type: "post",
				url: APP_CONFIG.verifyEmployeeUrl,
				data: data,
				success: function(res){
					if (checkServiceResult(res)) {
						window.localStorage.setItem("actName", name);
						window.localStorage.setItem("actNum", num);  
						window.location.href = "product_list.html"; 
                    }
				},
				complete: function(xhr, status) {
					$(".ensure").removeAttr('disabled');
				}
			});
		}		
	});	

	function checkName(str) {
		var strs = str.replace(/(^\s+)|(\s+$)/g, "");
		if (!(/^[\u4e00-\u9fa5]{2,5}$/.test(strs))) {
			$(".checkName").css("display","block");
			return false;
		}else{
			$(".checkName").css("display","none");
			return true;
		}
	}

	function checkNum(num){
		var nums = num.replace(/(^\s+)|(\s+$)/g, "");
		if(!(/^[A-Za-z0-9]{3,}$/.test(nums))){
			$(".checkNum").css("display","block");
			return false;
		}else{
			$(".checkNum").css("display","none");
			return true;
		}
	}
</script>
</html>